import wx, random, time


class MyFrame(wx.Frame):
    name_list = ["王欣淼", "张雅婷", "李嘉澳"]

    def __init__(self):
        wx.Frame.__init__(self, None, title="抽奖器", size=(600, 600), pos=(200, 200))

        # 创建字体
        self.font = wx.Font(25, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_MAX, wx.FONTWEIGHT_BOLD)

        # 设置背景
        self.SetBackgroundColour((230, 250, 250))

        self.pl = wx.Panel(self, size=(500, 500), pos=(0, 0))
        self.staticText_name = None
        self.timer = None
        self.entry = wx.TextCtrl(self.pl, size=(500, 50), pos=(50, 400), style=wx.TE_RIGHT)
        self.staticText = wx.StaticText(self.pl, label="欢迎你使用抽奖器", pos=(180, 30), style=wx.TE_CENTER)
        self.btn = wx.Button(self.pl, label="抽奖", pos=(270, 250))
        self.btn2 = wx.Button(self.pl, label="结束", pos=(270, 300))
        self.Bind(wx.EVT_BUTTON, self.onClick, self.btn)
        self.Bind(wx.EVT_BUTTON, self.onClick2, self.btn2)
        self.btn3 = wx.Button(self.pl, label="提交", pos=(270, 500))
        self.Bind(wx.EVT_BUTTON, self.onClick3, self.btn3)

        self.staticText.SetFont(self.font)

    def onClick(self, event):
        print("被点击")
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.update, self.timer)
        self.timer.Start(100)

    def update(self, event):
        self.staticText_name = wx.StaticText(self.pl, label=random.choice(MyFrame.name_list), pos=(260, 150))
        self.staticText_name.SetFont(self.font)

    def onClick2(self, event):
        print("被点击")
        self.timer.Stop()
        self.staticText.LabelText = f"抽奖结束，恭喜{self.staticText_name.LabelText}!"
        self.staticText.SetPosition((130, 30))

    def onClick3(self, event):
        print("被点击")
        print(self.entry.GetValue())
        # 内置函数 eval() 输入计算字符串，输出结果
        result = eval(self.entry.GetValue())
        self.entry.AppendText(str(result))
        self.entry.SetValue(str(result))


app = wx.App()
frm = MyFrame()
frm.Show()

app.MainLoop()
